package com.dbz.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dbz.entity.Business;
import com.dbz.entity.User;
import com.dbz.service.BusinessService;
import com.dbz.service.UserService;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RequestMapping("/business/")
@RestController
public class BusinessController {
    @Resource
    private BusinessService businessService;

    /**
     * 多条件分页查询
     * @param bname
     * @param bphone
     * @param page
     * @param rows
     * @return
     */
    @RequestMapping("selectBasiness")
    public Map pageList(String bname,String bphone,Integer page,Integer rows){
        Map<String,Object> map=new HashMap<>();
        QueryWrapper<Business> queryWrapper=new QueryWrapper<Business>();
        queryWrapper.like(bname!=""&&bname!=null,"bname",bname);
        queryWrapper.eq(bphone!=""&&bphone!=null,"bphone",bphone);
        IPage<Business> pages=new Page<Business>(page,rows);
        map.put("rows", businessService.selectPage(pages,queryWrapper).getRecords());
        map.put("total",businessService.selectPage(pages,queryWrapper).getTotal());
        return  map;
    }

    /**
     * 添加信息
     * @param bname
     * @param bphone
     * @return
     */
    @RequestMapping("insertBasiness")
    public int insertBasiness(String bname,String bphone){

        return businessService.insertBusiness(bname,bphone);
    }

    /**
     * 修改信息
     * @param bname
     * @param bphone
     * @return
     */
    @RequestMapping("updateBasiness")
    public int updateBasiness(String bid,String bname,String bphone){
        return businessService.updateBusiness(bid,bname,bphone);
    }
    /**
     * 删除信息
     * @param bid
     * @return
     */
    @RequestMapping("deleteBasiness")
    public int deleteBasiness(String bid){
        return businessService.delecteBusiness(bid);
    }

    /**
     * 查询全部
     * @return
     */
    @RequestMapping("selectAllBus")
    public List<Business> selectAllBus(){
        return businessService.selectAllBus();
    }
}
